package com.ala4.oxcafe.entity;

import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
import cn.idev.excel.annotation.ExcelProperty;
import com.ala4.oxcafe.boot.annotation.ExcelIntToStr;
import com.ala4.oxcafe.core.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 质保单
 *
 * @author PING
 * @version 1.0.0
 * @date 2025/8/15 17:27
 */
@Data
@ExcelIgnoreUnannotated
@EqualsAndHashCode(callSuper = true)
@TableName("warranty_order") // 指定实际表名
public class WarrantyOrder extends BaseEntity {

    @NotNull(message = "质保单ID不能为空", groups = {Update.class})
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private Long id;

    @NotNull(message = "服务单ID不能为空")
    private Long serviceId;

    @NotNull(message = "服务单号不能为空")
    @ExcelProperty("服务单号")
    @Schema(description = "服务单号")
    private String serviceNo;

    @ExcelProperty("质保单号")
    @Schema(description = "质保单号")
    @NotEmpty(message = "质保单号不能为空", groups = {Create.class, Update.class})
    private String warrantyNo;

    @ExcelProperty("客户名称")
    @Schema(description = "客户名称")
    @NotNull(message = "客户名称不能为空", groups = {Create.class, Update.class})
    @NotEmpty(message = "客户名称不能为空", groups = {Create.class, Update.class})
    private String customerName;

    @ExcelProperty("手机号")
    @Schema(description = "手机号")
    @NotEmpty(message = "手机号不能为空", groups = {Create.class, Update.class})
    private String customerPhone;

    @NotNull(message = "服务门店不能为空", groups = {ServiceOrder.Create.class, ServiceOrder.Update.class})
    private Long storeId;
    @Schema(description = "服务门店编码")
    private String storeCode;
    @Schema(description = "服务门店名称")
    private String storeName;

    @TableField("operator")
    @Schema(description = "施工人")
    @NotNull(message = "施工人不能为空", groups = {ServiceOrder.Create.class, ServiceOrder.Update.class})
    @NotEmpty(message = "施工人不能为空", groups = {ServiceOrder.Create.class, ServiceOrder.Update.class})
    @ExcelProperty("施工人")
    private String operator;

    @ExcelProperty("车牌号")
    @Schema(description = "车牌号")
    @NotEmpty(message = "车牌号不能为空", groups = {Create.class, Update.class})
    private String carPlate;

    @ExcelProperty("车架号")
    @Schema(description = "车架号")
    private String carVin;

    @ExcelProperty("车辆型号")
    @Schema(description = "车辆型号")
    private String carModel;

    @ExcelProperty("车辆颜色")
    @Schema(description = "车辆颜色")
    private String carColor;

    @ExcelProperty("施工日期")
    @Schema(description = "施工日期")
    @NotNull(message = "施工日期不能为空", groups = {Create.class, Update.class})
    private LocalDateTime serviceDate;

    @ExcelProperty("质保单年限(单位:月)")
    @Schema(description = "质保单年限(单位:月)")
    private Integer warrantyPeriod;

    @ExcelProperty("过保日期")
    @Schema(description = "过保日期")
    private LocalDate expiredDate;

    @ExcelProperty("保修状态")
    @ExcelIntToStr("0=生效中,1=已过保")
    @Schema(description = "保修状态(0=生效中,1=已过保)")
    @NotNull(message = "状态不能为空", groups = {Create.class, Update.class})
    private Integer status;
    @Schema(description = "服务产品明细")
    @TableField(exist = false)
    private List<ServiceOrderDetail> serviceOrderDetailList;

    public WarrantyOrder() {
    }

    public WarrantyOrder(ServiceOrder serviceOrder) {
        this.serviceId = serviceOrder.getId();
        this.serviceNo = serviceOrder.getServiceNo();
        this.customerName = serviceOrder.getCustomerName();
        this.customerPhone = serviceOrder.getCustomerPhone();
        this.carPlate = serviceOrder.getCarPlate();
        this.carVin = serviceOrder.getCarVin();
        this.carModel = serviceOrder.getCarModel();
        this.carColor = serviceOrder.getCarColor();
        this.serviceDate = serviceOrder.getServiceDate();
        this.storeId = serviceOrder.getStoreId();
        this.storeCode = serviceOrder.getStoreCode();
        this.storeName = serviceOrder.getStoreName();
    }

    // 分组校验接口定义
    public interface Create {
    }


    public interface Update {
    }
}
